<?php
define('GAME', 		'love');
define('ROOT', 		dirname(__FILE__) . '/');

define('WWWROOT_URL', 	'http://173.255.245.72/love_a_love/');

define('CFG_PATH_GAME', 		'path_game');
define('CFG_PATH_CDN', 			'path_cdn');
define('CFG_IS_ADMIN', 			'is_admin');

include_once ROOT . '../ujn2/ujn.php';

ujn_runtime::setSplitAlias('lilith');

function main(ujn_controller $c) { // 主頁面

	$uid = isset($_POST['uid']) ? $_POST['uid'] : 0;
	if(empty($uid)) { /* 使用js方式跳转 */
		$c->redirect(ujn::getCFG(CFG_PATH_GAME), 'js');
	}
	$_url		= isset($_POST['url'])		? $_POST['url'] : '';
	$_user		= isset($_POST['user'])		? $_POST['user'] : '';
	$_friends	= isset($_POST['friends'])	? $_POST['friends'] : '';
	$_time		= isset($_POST['time'])		? $_POST['time'] : '';
	$_sig		= isset($_POST['sig'])		? $_POST['sig'] : '';

	if($_sig != md5($_url . $uid . $_time . ujn::getCFG(CFG_PRIVATE_KEY) . $_friends . $_user)) die('unaccess, u need refresh!');

	$_url		= urldecode($_url);
	$_user		= urldecode($_user);
	$_friends	= urldecode($_friends);
	
	$pUser = json_decode($_user, true);
	$gUser = mdl_member_info::getInstance()->getMemberByUID($uid, $pUser['puid']);
	
	$c->assign(array(
		'p_user'  => $_user,
		'g_user'  => $gUser,
		'cdn_url' => ujn::getCFG(CFG_PATH_CDN),
		'img_url' => ujn::getCFG(CFG_PATH_CDN) . 'images/',
		'surplus' => mdl_member_vote::getInstance()->getSurplus($uid),
	));
	
	return $c;
}